/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.job;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserEnterprise;
import com.thinkgem.jeesite.modules.hk.sys.service.job.HkUserEnterpriseService;

/**
 * 用户企业信息Controller
 * @author 罗天文
 * @version 2018-08-02
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/job/hkUserEnterprise")
public class HkUserEnterpriseController extends BaseController {

	@Autowired
	private HkUserEnterpriseService hkUserEnterpriseService;
	
	@ModelAttribute
	public HkUserEnterprise get(@RequestParam(required=false) String id) {
		HkUserEnterprise entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserEnterpriseService.get(id);
		}
		if (entity == null){
			entity = new HkUserEnterprise();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:job:hkUserEnterprise:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserEnterprise hkUserEnterprise, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserEnterprise> page = hkUserEnterpriseService.findPage(new Page<HkUserEnterprise>(request, response), hkUserEnterprise); 
		model.addAttribute("page", page);
		return "hk/sys/job/hkUserEnterpriseList";
	}

	@RequiresPermissions("sys:job:hkUserEnterprise:view")
	@RequestMapping(value = "form")
	public String form(HkUserEnterprise hkUserEnterprise, Model model) {
		model.addAttribute("hkUserEnterprise", hkUserEnterprise);
		return "hk/sys/job/hkUserEnterpriseForm";
	}

	@RequiresPermissions("sys:job:hkUserEnterprise:edit")
	@RequestMapping(value = "save")
	public String save(HkUserEnterprise hkUserEnterprise, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserEnterprise)){
			return form(hkUserEnterprise, model);
		}
		hkUserEnterpriseService.save(hkUserEnterprise);
		addMessage(redirectAttributes, "保存用户企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserEnterprise/?repage";
	}
	
	@RequiresPermissions("sys:job:hkUserEnterprise:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserEnterprise hkUserEnterprise, RedirectAttributes redirectAttributes) {
		hkUserEnterpriseService.delete(hkUserEnterprise);
		addMessage(redirectAttributes, "删除用户企业信息成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserEnterprise/?repage";
	}

}